<?php
require_once ('DataController/AdapterBase.php');

/**
 * @author Shuichi
 * @version 1.0
 * @created 28-6-2008 2:22:02
 */
class EventAdapter extends AdapterBase
{


	private static $DELETE_STRING = "delete from events where mailid=:mailid";

	private static $INSERT_STRING = "insert into events 
									(mailid, 
									place,
									eventdate,	
									starttime,
									endtime,
									numberofpeople,
									comment,
									postuserid,
									eventstatus,
									adddate,
									adduserid,
									updatedate,
									updateuserid) 
									values 
									(
									:mailid, 
									:place,
									:eventdate,	
									:starttime,
									:endtime,
									:numberofpeople,
									:comment,
									:postuserid,
									:eventstatus,
									now(),
									:adduserid,
									now(),
									:updateuserid)";

	private static $SELECT_STRING = "select events.*,
								case
								when users.username is null then
									substring(emailaddress, 1, instr(emailaddress,'@')-1)
								else
									users.username
								end
								as username,
								users.emailaddress,
								mails.subject
								from events 
								inner join
								users
								on events.postuserid = users.userid
								inner join mails
								on
								events.mailid = mails.mailid
								where 0 = 0 ";

	static $UPDATE_STRING = "update events set
									mailid = :mailid,
									place = :place,
									eventdate = :eventdate,
									starttime = :starttime,
									endtime = :endtime,
									numberofpeople = :numberofpeople,
									comment = :comment,
									postuserid = :postuserid,
									eventstatus = :eventstatus,
									updatedate = now(),
									updateuserid = :updateuserid
									 where mailid = :mailid
									 ";
									 
	public static $MAILID = "mailid";
	public static $PLACE = "place";	
	public static $EVENTDATE = "eventdate";
	public static $STARTTIME = "starttime";	
	public static $ENDTIME = "endtime";
	public static $NUMBEROFPEOPLE = "numberofpeople";
	public static $COMMENT = "comment";	
	public static $POSTUSERID = "postuserid";
	public static $EVENTSTATUS = "eventstatus";									 
	public static $ADDDATE = "adddate";
	public static $ADDUSERID = "adduserid";
	public static $UPDATEDATE = "updatedate";
	public static $UPDATEUSERID = "updateuserid";
	public static $USERNAME = "username";
	public static $EMAILADDRESS= "emailaddress";
	public static $SUBJECT= "subject";
	public static $EVENT_MAILID = "events.mailid";

	public function __construct()
	{
		parent::__construct();
		$this->insertString = EventAdapter::$INSERT_STRING;
		$this->updateString = EventAdapter::$UPDATE_STRING;
		$this->deleteString = EventAdapter::$DELETE_STRING;
	}

	/**
	 * @return
	 * @param $parameters Object
	 * 
	 * @param parameters    parameters
	 */
	public function setSelectString($parameters)
	{
		$this->selectString = EventAdapter::$SELECT_STRING;

		if(is_array($parameters))
		{
			parent::setSelectString($parameters);		
		}
		$this->selectString .= " order by mailid asc";
	}
	
	public function setSelectStringString($selectString, $parameters)
	{
		$this->selectString = $selectString;

		if(is_array($parameters))
		{
			parent::setSelectString($parameters);		
		}
		$this->selectString .= " order by eventdate asc";
	}

	public function insert($parameters)
	{

		parent::insert($parameters);
	}
}
?>